<template>
  <a-drawer width="35%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
    <a-divider orientation="left">
      <b>{{ formTitle }}</b>
    </a-divider>
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-form-model-item label="状态" prop="status" >
      </a-form-model-item>
      <a-form-model-item label="删除标志" prop="delFlag" v-if="formType === 1">
        <a-input v-model="form.delFlag" placeholder="请输入删除标志" />
      </a-form-model-item>
      <a-form-model-item label="订单id" prop="orderId" >
        <a-input v-model="form.orderId" placeholder="请输入订单id" />
      </a-form-model-item>
      <a-form-model-item label="原用户id" prop="oldUserId" >
        <a-input v-model="form.oldUserId" placeholder="请输入原用户id" />
      </a-form-model-item>
      <a-form-model-item label="原用户名称" prop="oldUserName" >
        <a-input v-model="form.oldUserName" placeholder="请输入原用户名称" />
      </a-form-model-item>
      <a-form-model-item label="原用户手机号" prop="oldUserPhone" >
        <a-input v-model="form.oldUserPhone" placeholder="请输入原用户手机号" />
      </a-form-model-item>
      <a-form-model-item label="原店铺id" prop="oldStoreId" >
        <a-input v-model="form.oldStoreId" placeholder="请输入原店铺id" />
      </a-form-model-item>
      <a-form-model-item label="原店铺名称" prop="oldStoreName" >
        <a-input v-model="form.oldStoreName" placeholder="请输入原店铺名称" />
      </a-form-model-item>
      <a-form-model-item label="原店铺店长" prop="oldStoreLeader" >
        <a-input v-model="form.oldStoreLeader" placeholder="请输入原店铺店长" />
      </a-form-model-item>
      <a-form-model-item label="原店铺店长id" prop="oldStoreLeaderId" >
        <a-input v-model="form.oldStoreLeaderId" placeholder="请输入原店铺店长id" />
      </a-form-model-item>
      <a-form-model-item label="原店铺店长手机号" prop="oldStoreLeaderPhone" >
        <a-input v-model="form.oldStoreLeaderPhone" placeholder="请输入原店铺店长手机号" />
      </a-form-model-item>
      <a-form-model-item label="类型 1更换卖家 2转移单子 3转移单+人" prop="type" >
      </a-form-model-item>
      <a-form-model-item label="新用户id" prop="newUserId" >
        <a-input v-model="form.newUserId" placeholder="请输入新用户id" />
      </a-form-model-item>
      <a-form-model-item label="新用户名称" prop="newUserName" >
        <a-input v-model="form.newUserName" placeholder="请输入新用户名称" />
      </a-form-model-item>
      <a-form-model-item label="新用户手机号" prop="newUserPhone" >
        <a-input v-model="form.newUserPhone" placeholder="请输入新用户手机号" />
      </a-form-model-item>
      <a-form-model-item label="接收状态 0待审核 1同意 2拒绝" prop="receiveStatus" >
      </a-form-model-item>
      <a-form-model-item label="新店铺id" prop="newStoreId" >
        <a-input v-model="form.newStoreId" placeholder="请输入新店铺id" />
      </a-form-model-item>
      <a-form-model-item label="新店铺名称" prop="newStoreName" >
        <a-input v-model="form.newStoreName" placeholder="请输入新店铺名称" />
      </a-form-model-item>
      <a-form-model-item label="新店铺店长" prop="newStoreLeader" >
        <a-input v-model="form.newStoreLeader" placeholder="请输入新店铺店长" />
      </a-form-model-item>
      <a-form-model-item label="新店铺店长id" prop="newStoreLeaderId" >
        <a-input v-model="form.newStoreLeaderId" placeholder="请输入新店铺店长id" />
      </a-form-model-item>
      <a-form-model-item label="新店铺店长手机号" prop="newStoreLeaderPhone" >
        <a-input v-model="form.newStoreLeaderPhone" placeholder="请输入新店铺店长手机号" />
      </a-form-model-item>
      <div class="bottom-control">
        <a-space>
          <a-button type="primary" :loading="submitLoading" @click="submitForm">
            保存
          </a-button>
          <a-button type="dashed" @click="cancel">
            取消
          </a-button>
        </a-space>
      </div>
    </a-form-model>
  </a-drawer>
</template>

<script>
import { getChangeOrder, addChangeOrder, updateChangeOrder } from '@/api/system/changeOrder'

export default {
  name: 'CreateForm',
  props: {
  },
  components: {
  },
  data () {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        id: null,

        status: '0',

        delFlag: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        orderId: null,

        oldUserId: null,

        oldUserName: null,

        oldUserPhone: null,

        oldStoreId: null,

        oldStoreName: null,

        oldStoreLeader: null,

        oldStoreLeaderId: null,

        oldStoreLeaderPhone: null,

        type: null,

        newUserId: null,

        newUserName: null,

        newUserPhone: null,

        receiveStatus: '0',

        newStoreId: null,

        newStoreName: null,

        newStoreLeader: null,

        newStoreLeaderId: null,

        newStoreLeaderPhone: null

      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    onClose () {
      this.open = false
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        id: null,

        status: '0',

        delFlag: null,

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        orderId: null,

        oldUserId: null,

        oldUserName: null,

        oldUserPhone: null,

        oldStoreId: null,

        oldStoreName: null,

        oldStoreLeader: null,

        oldStoreLeaderId: null,

        oldStoreLeaderPhone: null,

        type: null,

        newUserId: null,

        newUserName: null,

        newUserPhone: null,

        receiveStatus: '0',

        newStoreId: null,

        newStoreName: null,

        newStoreLeader: null,

        newStoreLeaderId: null,

        newStoreLeaderPhone: null

      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (row, ids) {
      this.reset()
      this.formType = 2
      const id = row ? row.id : ids
      getChangeOrder(id).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
          if (this.form.id !== undefined && this.form.id !== null) {
            updateChangeOrder(this.form).then(response => {
              this.$message.success(
                '修改成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          } else {
            addChangeOrder(this.form).then(response => {
              this.$message.success(
                '新增成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>
